package com.feicheng.iou.controller;


import com.feicheng.iou.commom.ReturnCode;
import com.feicheng.iou.entity.Resource;
import com.feicheng.iou.exception.SystemException;
import com.feicheng.iou.result.ResultInfo;
import com.feicheng.iou.service.ResourceRecordService;
import com.feicheng.iou.service.ResourceService;
import com.feicheng.iou.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tianchunlei
 * @since 2021-06-28
 */
@RestController
@RequestMapping("/iou/student")
@Slf4j
public class StudentController {

    @Autowired
    private StudentService studentService;  //学生实现类

    @Autowired
    private ResourceService resourceService; //线索实现类

    @Autowired
    private ResourceRecordService resourceRecordService; //线索记录实现类

    /**
     * @Author wuweinan
     * @Description 查看个人详情接口
     * @Date 2021-6-29 17:19
     * @param studentId
     * @return ResultInfo
     */
    @GetMapping("/info/{studentId}")
    public ResultInfo queryPersonalDetail(@PathVariable("studentId") Integer studentId){
        log.info("StudentController的queryPersonalDetail方法进入");
        if(studentId == null){
            throw new SystemException(ReturnCode.PARAM_NOT_NULL);
        }


        //根据studentId查询Student,ServiceImpl层包含将结果存入Map的操作
        studentService.selectStudentById(studentId);

        //根据studentId查询Resource,ServiceImpl层包含将结果存入Map的操作
        Resource resource = resourceService.selectResourceByStudentIdPersonalDetail(studentId);

        //获取根据StudentId查询到resourceId（毕竟一对一），用来查询resourceRecordId.
        Integer resourceId = resource.getId();

        //获取resource线索对象集合 resourceRecords,ServiceImpl层包含将结果存入Map的操作
        log.info("StudentController的queryPersonalDetail方法返回");
        return    resourceRecordService.selectResourceRecordByResourceId(resourceId);

    }
}

